<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>品牌管理</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/backStyle.css">
<link rel="stylesheet" href="css/style.css"></link>
<link rel="stylesheet" type="text/css" href="css/myButton.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap-modal.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>

<style>
html,body {
	height: 100%;
	width: 100%;
	border: 0;
	background: #fff;
	overflow-y: auto;
}

.button {
	margin-top: 1.5em;
	margin-left: 12em;
}

label {
    width: 8em;
}
</style>
</head>
<body>
	<ul class="breadcrumb">
		<li><a href="sys/welcome.jsp">首页</a></li>
		<li class="active"><a href="brandShow.action">品牌管理</a></li>
		<li class="active">品牌查看</li>
	</ul>
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="form">
				<form action="brandEdit.action" id="brandInfor">
					<s:if test="brand.id!=null">
						<input name="brand.id" type="hidden" value="<s:property value="brand.id"/>">
						<p>
							<label>品牌编号：</label>
							<span><s:property value="brand.id"/></span>
						</p>
						<p>
							<label>品牌名：</label>
							<span><input type="text" name="brand.brandname" value="<s:property value="brand.brandname"/>"  id="brandName"/></span>
							<span class="redstar">*</span>
						</p>
					</s:if>
					<s:else>
						<p>
							<label>品牌中文名：</label>
							<span><input type="text" id="brandNameCn" onblur="getBrandName()"/></span>
							<span class="redstar">*</span>
						</p>
						<p>
							<label>品牌英文名：</label>
							<span><input type="text" id="brandNameEn" onblur="getBrandName()"/></span>
							<span class="redstar">*</span>
						</p>
						<p>
							<label>品牌名(生成)：</label>
							<span><input type="text" name="brand.brandname" id="brandName" onfocus="getBrandName()" readonly="readonly"/></span>
						</p>
					</s:else>
					<input id="brandInforSubmit" type="button" value="保存品牌信息" onclick="brandCheck()" class="button black">
				</form>
				</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	function getBrandName() {
		if($("#brandNameCn") != null && $("#brandNameEn") != null) {
			$("#brandName").val($("#brandNameCn").val()+"("+$("#brandNameEn").val()+")");
		}
	}
	function brandCheck() {
		var brandName = $("#brandName").val();
		if (brandName.length<1||brandName.length>64) {
			alert("请输入不超过64位的品牌名");
			document.getElementById("brandName").focus();
			$("#brandName").val("${brand.brandname}");
			return false;
		}
		if (confirm('您是否要保存品牌？')) {
			$.ajax({
				url : "brandEdit.action",
				type : "post",
				dataType : "json",
				data : $("#brandInfor").serialize(),
				success : function(data) {
					var flag = JSON.parse(data).flag;
					if (flag == "success") {
						alert("保存品牌成功！");
						window.location.href = "brandShow.action";
					} else {
						alert("保存品牌失败！");
					}
				}
			});
		} else {
			return false;
		}
	}
</script>
</html>
